﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;

namespace 双向绑定1改进方案
{
    public class Data : INotifyPropertyChanged
    {
        #region 属性改变通知
        public event PropertyChangedEventHandler PropertyChanged;
        protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
        {
            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
        }

        #endregion

        #region 属性单例模式

        private static readonly Lazy<Data> Instance = new Lazy<Data>(() => new Data());

        private Data()
        {
        }

        public static Data Ins { get; } = Instance.Value;

        #endregion 属性单例模式

        private string string1 = "str1";
        private  string string2 = "str2";

        public  string String1 
        { 
            get => string1;
            set
            {
                string1 = value;
                OnPropertyChanged();
            }
        }
        public  string String2
        { 
            get => string2; 
            set
            {
                string2 = value;
                OnPropertyChanged();
            }
        }

  
    }

}
